package servlet;

import bean.House_info;
import util.DBUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/List")
public class List extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String sql ="select * from house_info i, house_type t where i.house_type_id=t.id";
        ResultSet rs = DBUtil.query(sql);
        ArrayList<House_info> list=new ArrayList<>();
        try {
            while(rs.next()){
                int id = rs.getInt("i.id");
                int typeId = rs.getInt(6);
                String mode = rs.getString(2);
                double rent = rs.getDouble(3);
                String contact = rs.getString(4);
                String method = rs.getString(5);
                String address = rs.getString(7);
                String type = rs.getString(9);
                House_info info = new House_info(id, mode, rent, contact, method, typeId, address, type);
                list.add(info);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.setAttribute("list",list);
        request.getRequestDispatcher("/WEB-INF/list.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
